//
//  PCDApiSetUserInfo.m
//  PCDBankSix
//
//  Created by Jason Tao on 2022/4/28.
//

#import "PCDApiSetUserInfo.h"
#import "PCDLoginSession.h"
#import "PCDDataBaseModel.h"

@implementation PCDApiSetUserInfo

- (void)handler:(id)data andContext:(PCDContext *)context ResponseCallback:(WVJBResponseCallback )responseCallback
{
    NSString * userInfoRes = data[@"UserInfo"];
    NSString * successFunc = data[@"success"];
    if (userInfoRes) {
        NSDictionary * dicInfo = [userInfoRes JSONValue];
        PCDLoginSession * loginSession = [[PCDLoginSession alloc] initWithDict:dicInfo];
        [PCDUtil saveLoginSession:loginSession];
		
//		NSString *phone = [[loginSession.CUST_MOBILE componentsSeparatedByString:@"|"] firstObject];
		NSString *phone = [[PCDDataBaseModel shareModel].memoryStorage objectForKey:@"registerPhone"];
		[PCDUtil saveCacheUserName:phone];
		
		NSDictionary *userInfo = @{@"loginId": phone?:@"",@"name":loginSession.CUST_NAME?:@"",@"headImage":loginSession.HEAD_URL?:@""};
		[PCDUtil saveUserInfo:userInfo];
		//发通知
		[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Login object:nil];
    }
    evaluateJavaScriptOnMainThread(self,successFunc,([@{@"statu":@"1",@"msg":@"设置成功"} JSONRepresentation]));

}

@end
